package com.younion.action.consumer.impl;

import java.text.SimpleDateFormat;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.younion.action.consumer.AbstractRequestConsumer;
import com.younion.action.interactive.mobile.ApiConstant;
import com.younion.action.interactive.mobile.ResultObject;
import com.younion.business.IActiveService;
import com.younion.common.constants.SysConstants;
import com.younion.model.ActiveDetailResult;
import com.younion.util.HttpRequestUtils;
import com.younion.util.JsonUtils;
import com.younion.util.config.ConfigHelper;
import com.younion.vo.ActiveVO;

public class ActivityGetConsumer extends AbstractRequestConsumer {
	private IActiveService activeService;

	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return getActivity(request, response);
	}

	public String getActivity(HttpServletRequest request,
			HttpServletResponse response) {
		ActiveDetailResult activeDetailResult = new ActiveDetailResult();
		ActiveVO activeVO = null;
		ResultObject resultObject = new ResultObject();
		String id = request.getParameter("id");
		try {
			activeVO = activeService.getById(id);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
			if (activeVO != null) {
				String img_url_pre = ConfigHelper.fastGetConfig("interface",
						"img_url_pre", "http://localhost:8080/younonmember/");
				activeDetailResult.setId(activeVO.getId().toString());
				activeDetailResult.setPic(img_url_pre
						+ SysConstants.ACTIVE_IMG_PATH + "/" + activeVO.getId()
						+ "/" + activeVO.getPicName());
				activeDetailResult.setTitle(activeVO.getTitle());
				activeDetailResult.setDescription(activeVO.getDescription());
				activeDetailResult.setTop(activeVO.getTop().toString());
				activeDetailResult.setStartTime(sdf.format(activeVO.getStartTime()));
				activeDetailResult.setEndTime(sdf.format(activeVO.getEndTime()));
				activeDetailResult.setInstruction(activeVO.getInstruction());
			}
			resultObject.setResult(activeDetailResult);
			resultObject.setStatus(ApiConstant.SUCCESS_STATUS);
		} catch (Exception e) {
			resultObject.setStatus(ApiConstant.FALSE_STATUS);
			resultObject.setMsg(ApiConstant.PUBLIC_EXCEPTION);
			e.printStackTrace();
		}
		HttpRequestUtils.printContent(JsonUtils.parseObj2Json(resultObject),
				response);
		return null;
	}

	public IActiveService getActiveService() {
		return activeService;
	}

	public void setActiveService(IActiveService activeService) {
		this.activeService = activeService;
	}

}
